<?php
/***************************************************************************
 *   copyright : (C) 2009 Udrea Cristian
 *   site : http://code.google.com/p/testauction-php
 ***************************************************************************/

/***************************************************************************
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU Lesser General Public License as 
 *   published by the Free Software Foundation; either version 2 of the
 *   License, or (at your option) any later version. Although none of the
 *   code may be sold. If you have been sold this script, get a refund.
 ***************************************************************************/
function loadFromFile($filename){
	$fh = fopen($filename, 'r');
	$theData = fread($fh, filesize($filename));
	fclose($fh);
	return eval($theData);
}

include("elements/piece.header.php");

$lastClosed = $auctionDB->getLastClosedAuctions();

// Licitatii active sau terminate
if(!isset($_GET['page']) || $_GET['page'] == 1 || $_GET['page'] == 2)
{
	$template->setCurrentBlock("box_page");
	$boxes = "";
	$script_var = "";
	
	if(!isset($_GET['page']) || $_GET['page'] == 1 || !is_numeric($_GET['page'])){
		// Construieste lista de licitatii active
		$result = $auctionDB->getOpenAuctions();
		$script_var .="<script type=\"text/javascript\">";
		foreach($result as $item) {
			$min = (integer)$item['time_left'] / 60;
			$sec = $item['time_left'] % 60;
			$auctionactive_box->setAuctionID($item['auction_id']);
			$boxes .= $auctionactive_box->toString();
			$script_var .= "auction_id_array.push([".$item['auction_id'].", ".(($item['starts_timestamp'] < time())?$min:0).", ".(($item['starts_timestamp'] < time())?$sec:0).", 0]);";
		}
		$script_var .= "refreshItems(); countDown(); </script>";
	}

	if($_GET['page'] == 2){
		// Construieste lista de licitatii terminate
		foreach($lastClosed as $item) {
			$auctionsold_box->setAuctionID($item['auction_id']);
			$boxes .= $auctionsold_box->toString();
		}
	}

	$template->setVariable("PRODUCTBOXES", $boxes . $script_var);
	$template->parseCurrentBlock();
//Pagini incarcate dinamic
}else{
	$template->setCurrentBlock("table_page");
	if($_GET['page'] == 3)
		$template->setVariable("TABLEPAGECONTENT", loadFromFile("templates/ideea.ev"));// LOC PTR PAGINA : IDEEA
	if($_GET['page'] == 4)
		$template->setVariable("TABLEPAGECONTENT", loadFromFile("templates/reguli.ev"));// LOC PTR PAGINA : REGULI
	if($_GET['page'] == 5)
		$template->setVariable("TABLEPAGECONTENT", loadFromFile("templates/ghid_user.ev"));
	if($_GET['page'] == 6)
		$template->setVariable("TABLEPAGECONTENT", loadFromFile("templates/faq.ev"));
	if($_GET['page'] == 7)
		$template->setVariable("TABLEPAGECONTENT", loadFromFile("templates/contact.ev"));
	if($_GET['page'] == 8)
		$template->setVariable("TABLEPAGECONTENT", "LOC PTR PAGINA : METODE DE PLATA");
	
	if($_GET['page'] == 20)
		include("pages/register.php");
	if($_GET['page'] == 21)
		include("pages/forgotpass.php");
	if($_GET['page'] == 22) {
		include("pages/confirm.php");
		if($confirm->isval($_GET['code']) && $confirm->isval($_GET['cnf'])) {
			$template->setVariable("TABLEPAGECONTENT", $confirm->confirmAccount($_GET['code'], $_GET['cnf']));
		}
		else {
			include("index.php");
		}
	}
	if($_GET['page'] == 23)
		include("pages/useredit.php");
	if($_GET['page'] == 24) {
		if(isset($_GET['id'])) {
			include("pages/details.php");
		}
		else {
			include("index.php");
		}
	}
	if($_GET['page'] == 25) {
		include('pages/buycredits.php');
	}
}
include("elements/piece.footer.php");
?>
